const express = require('express')
const crypto = require('crypto')
const app = express()
app.listen(3000, '0.0.0.0')
app.use(express.static('www'))

app.get('/', (req, res) => {
  // 得到客户发送过来的加密key
  const secWebsocketKey = 'DMgyvjE4wuo/bQNumuWirw==';//req.headers['sec-websocket-key'];
  // 通过rfc6455协议中找到websocket加密码所需要的guid
  const guid = '258EAFA5-E914-47DA-95CA-C5AB0DC85B11';
  const secWebSocketAccept = crypto.createHash('sha1').update(secWebsocketKey + guid).digest('base64')

  res.writeHead(101, {
    Connection: 'Upgrade',
    'Sec-WebSocket-Accept': secWebSocketAccept,
    Upgrade: 'websocket',
    'aa': 'aaaaa'
  });
  res.end('')
})
/*

*/

